<?php

/** 
 * @category		
 * @package		Lib			
 * @subpackage	Action	
 * @author		wanght <whtaok@gmail.com>
 * @since		2013-3-3
 * @version		$Id: AppAction.class.php 42 2013-10-30 03:34:30Z whtaok@gmail.com $
 */

class AppAction extends Action {
	protected $usingModel = '';
	
	/**
	 * 描述：分页设置
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-5-1
	 */
	public function listPage($model) {
		$nowPage = isset($_REQUEST['p'])?$_REQUEST['p']:1;
		import('ORG.Util.Page');
		$totalRows = $model->count();
		$listRows = 20;
		$pageObj = new Page($totalRows,$listRows);
		$list = $model->page($nowPage,$listRows)->select();
		$page = $pageObj->show();
		$rtn_data = array('list'=>$list,'page'=>$page);
		return $rtn_data;	
	}
	
	/*
	 * 通用是否显示内容
	* */
	public function isShowAct(){
		$id     = intval($_REQUEST['id']);
		$col_name   = trim($_REQUEST['col_name']);
		$data['id'] = $id;
		$data[$col_name] = array('exp',"($col_name+1)%2");
		$model = D($this->usingModel);
		$model->save($data);
		$result = $model->find($id);
		$this->ajaxReturn($result[$col_name]);
	}
	/*
	 * 通用排序方法单个排序
	* */
	public function ordlistAct(){
		$id     = intval($this->_param('id'));
		$col_name  = trim($this->_param('col_name'));
		$col_value =trim($this->_param('col_value'));
		if(!is_numeric($col_value)){
			$model = D($this->usingModel);
			$values = $model->find($id);
			$this->ajaxReturn($values[$col_name]);
		}else{
			$model = D($this->usingModel);
			$data['id'] = $id;
			$data[$col_name] = $col_value;
			$model->save($data);
			$this->ajaxReturn($col_value);
		}
		
	}
	
	/**
	 * 描述：当用户更改账号信息或公司信息时进行刷新session
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-4-14
	 */
	protected function mysession_refresh($userId){
		//用户信息
		$mod = new ShopUserModel();
		$detailShopUser = $mod->find($userId);
		
		$user = array(
				'account'=>$detailShopUser['account'],
				'mobile'=>$detailShopUser['mobile'],
				'name'=>$detailShopUser['name'],
				'sex'=>$detailShopUser['sex'],
				'logo'=>$detailShopUser['logo'],
		);
		//店铺信息
		$mod = new ShopLibModel();
		$detailShopLib = $mod->find($detailShopUser['shop_id']);
	
		$shop = array(
				'name'=>$detailShopLib['name'],
				'title'=>$detailShopLib['title'],
				'address'=>$detailShopLib['address'],
				'link_man'=>$detailShopLib['link_man'],
				'link_way'=>$detailShopLib['link_way'],
				'code'=>$detailShopLib['code'],
		);
		session(SES_USER_ID,$userId);
		session(SES_SHOP_ID,$detailShopUser['shop_id']);
		session(SES_USER,$user);
		session(SES_SHOP,$shop);
	}
	
}

?>